var count = 0;

var messagePoll = function(scope, key) {
  var d = '';

  function parseOption(val) {
    var options = val.split("^").pop().split("&");
    return {
      domain: options[0],
      data: window.unescape(options[1])
    }
  }

  function callback() {
    var val = scope[key];
    if (val != d) {
      // debugger
      console.log('xd里面的情况', document.domain, window.name);
      d = val;
      clearInterval(timeInterval);
      messageHandler(parseOption(val))
    }
  }
  var timeInterval = setInterval(callback, 1000 / 20)
};

function messageHandler(data) {
  console.log('从外面传进来了', data)
  console.log('打开登录页面')
  console.log('你输入了用户名密码')
  console.log('你点了登录按钮')
  Authorize({
    access_code: 'qwertyuiopasdfghjklzxcvbnm123456789'
  })
}


console.log('are you ok')

messagePoll(window, 'name');


function Authorize(options) {
  var jsonData = options || {};
  jsonData.success = 1;
  jsonData.status = 1;
  if (jsonData.error_code) {
    jsonData.success = -1;
    jsonData.status = -1
  }
  var sResult = JSON.stringify(jsonData);
  var oData = {
    data: sResult,
    requestType: "login"
  };
  var data = t.param(oData);
  data = escape(data);

  window.parent.name = (new Date()).getTime() + (count++) + "^" + document.domain + "&" + window.escape(data)

}
